
import pygame
from pygame.locals import *
from images import KNIGHT


class Unit (pygame.sprite.Sprite):

    def __init__ (self, container):
        "Position is a tuple of (x,y)."
        pygame.sprite.Sprite.__init__(self, container)

        self.health = [10.0, 10.0]
        self.damage = 3.0
        self.attack_speed = [0.0, 1.5]
        self.speed = 75
        self.exp = [0, 50]

    def getHealth (self, value=None):
        """ Returns: self.health[0]
            optional value arg for increasing or decreasing health """
        
        hp = self.health
        if value:
            new_health = hp[0] + value
            if new_health > hp[1]:
                hp[0] = hp[1]
                return hp[0]
            elif new_health <= 0:
                hp[0] = 0
                return hp[0]
            else:
                return hp[0] + value
        else: 
            return hp[0]

    def setPosition(self, position):
        self.rect.center = position

    def levelUp (self):

        new_health = int(self.health[1] * 1.3)
        self.health[0] += new_health
        self.health[1] += new_health
        self.speed += 1

#    def update (self):

#        pass


class Knight(Unit):

    container = pygame.sprite.Group()
    def __init__(self, container):
        Unit.__init__(self, container)
        self.image = KNIGHT
        self.rect = self.image.get_rect()

